package com.wx.business.course.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eachonline.core.Pagination;
import com.eachonline.mapper.GenericMapper;
import com.eachonline.service.GenericServiceImpl;
import com.eachonline.util.StringUtil;
import com.wx.business.course.IxbCourseCommentService;
import com.wx.dao.mapper.IxbCourseCommentMapper;
import com.wx.model.IxbCourseComment;
import com.wx.model.IxbCourseCommentExample;
@Service("ixbCourseCommentService")
public class IxbCourseCommentServiceImpl extends GenericServiceImpl<IxbCourseComment, IxbCourseCommentExample, String> implements IxbCourseCommentService  {

	
	@Autowired
	public IxbCourseCommentMapper  ixbCourseCommentMapper;
	
	@Override
	protected GenericMapper<IxbCourseComment, IxbCourseCommentExample, String> getGenericMapper() {
		// TODO Auto-generated method stub
		return this.ixbCourseCommentMapper;
	}

	@Override
	public void insertCourseComment(String content,String courseId,String courseTitile,int starlevel,String userId,String  userName,String userPic,String commentImageUrl) {
		// TODO Auto-generated method stub
		IxbCourseComment comment=new IxbCourseComment();
		comment.setContent(content);
		comment.setCourseId(courseId);
		comment.setCourseTitile(courseTitile);
		comment.setStartLevel(starlevel);
		comment.setUserId(userId);
		comment.setUserName(userName);
		comment.setUserPic(userPic);
		comment.setCommentImageUrl(commentImageUrl);
		comment.setCreateTime(new Date());
		if(StringUtil.isNotEmpty(commentImageUrl))
		{
			comment.setIsPic(1);
		}
		
		getGenericMapper().insert(comment);
	}

	@Override
	public Pagination<IxbCourseComment> selectCourseCommentByPage(
			IxbCourseCommentExample ext, int start, int pageSize, int isPic) {
		// TODO Auto-generated method stub
		Pagination<IxbCourseComment> pagination = new Pagination<IxbCourseComment>(start, pageSize);
		ext.setPagination(pagination);


		List<IxbCourseComment> list = this.getGenericMapper().selectByExample(ext);
		int count = this.getGenericMapper().countByExample(ext);

		pagination.setDataList(list);
		pagination.setTotalRowNumber(count);

		return pagination;
	}

	
}
